import json
def update_choice(type,keyName,chinese):
    updateData=json.load(open('./res/resData.json','r'))
    resData=updateData['res']
    resKeys=list(resData.keys())
    resValues=list(resData.values())
    for find_key in resKeys:
        if type==find_key:
            temp=resData[find_key]
            goalKeys=list(temp.keys())
            goalValues=list(temp.values())
            temp[keyName] = chinese
            resData[find_key] = temp
            updateData['res'] = resData
            jsondata = json.dumps(updateData, indent=4, separators=(',', ':'))
            f = open('./res/resData.json', 'w')
            f.write(jsondata)
            f.close()
            break
        else:
            print('no such res!')
def update_factor(type,nameCN):
    updateData = json.load(open('./res/resData.json',encoding='utf-8'))
    resData = updateData['res']
    resKeys = list(resData.keys())
    resValues = list(resData.values())
    for find_key in resKeys:
        if type==find_key:
            print('res is existed!')
            break
        else:
            resData[type]={}
            updateData['res'] = resData
            NewKey=updateData['nameCN']
            NewKey[type]=nameCN
            updateData['nameCN']=NewKey
            jsondata = json.dumps(updateData, indent=4, separators=(',', ':'))
            f = open('./res/resData.json','w')
            f.write(jsondata)
            f.close()

def get_res(type):
    Data = json.load(open('./res/resData.json', encoding='utf-8'))
    resData = Data['res']
    print(resData[type])
    return resData[type]